Model fit

Column

Assumption checks

Column

Indices of model fit

Metric Value
AIC 207.07
AICc 207.11
BIC 256.98
R2 (cond.) 1.00
R2 (marg.) 0.02
ICC 1.00
RMSE 0.02
Sigma 1.00
Log_loss 1.40e-03
Score_log -2.63
Score_spherical 0.02

For interpretation of performance metrics, please refer to this documentation.

Parameter estimates

Column

Plot

Column

Tabular summary

# Fixed Effects
Parameter Log-Odds SE 95% CI z p
(Intercept) -14.82 1.63 (-18.02, -11.62) -9.08 < .001
cluster [cluster_1] -9.88 4.84 (-19.36, -0.41) -2.04 0.041
cluster [cluster_2] 1.19 1.65 (-2.05, 4.44) 0.72 0.471
cluster [cluster_4] -13.08 6.24 (-25.32, -0.85) -2.10 0.036
cluster [cluster_5] -0.91 3.97 (-8.69, 6.86) -0.23 0.818
baseline bipolar I dx [1] 0.28 3.72 (-7.01, 7.57) 0.07 0.940
sex [M] -11.29 2.98 (-17.13, -5.45) -3.79 < .001
# Random Effects
Parameter Coefficient
SD (Intercept: family_id) 55.50

To find out more about table summary options, please refer to this documentation.

Predicted Values

Column

Plot

Column

Tabular summary

Model-based Expectation
cluster family_id Predicted SE 95% CI
cluster_3 4.57e-12 1.74e-11 (0.00, 0.00)
cluster_1 2.22e-16 1.49e-15 (0.00, 0.00)
cluster_2 1.51e-11 5.69e-11 (0.00, 0.00)
cluster_4 2.22e-16 1.79e-15 (0.00, 0.00)
cluster_5 1.84e-12 1.06e-11 (0.00, 0.00)

Variable predicted: Y4_bipolar_I_dx

Predictors modulated: cluster

Predictors controlled: baseline_bipolar_I_dx (0), sex (M)

Model-based Expectation
baseline_bipolar_I_dx family_id Predicted SE 95% CI
0.00 4.57e-12 1.74e-11 (0.00, 0.00)
1.00 6.04e-12 3.14e-11 (0.00, 0.00)

Variable predicted: Y4_bipolar_I_dx

Predictors modulated: baseline_bipolar_I_dx

Predictors controlled: cluster (1), sex (M)

Model-based Expectation
sex family_id Predicted SE 95% CI
M 4.57e-12 1.74e-11 (0.00, 0.00)
F 3.67e-07 5.98e-07 (0.00, 0.00)

Variable predicted: Y4_bipolar_I_dx

Predictors modulated: sex

Predictors controlled: cluster (1), baseline_bipolar_I_dx (0)

Text reports

Column

Textual summary

We fitted a logistic mixed model (estimated using ML and nlminb optimizer) to predict Y4_bipolar_I_dx with cluster, baseline_bipolar_I_dx and sex (formula: as.factor(Y4_bipolar_I_dx) ~ cluster + as.factor(baseline_bipolar_I_dx) + as.factor(sex)). The model included family_id as random effect (formula: ~1 | family_id). The model’s total explanatory power is substantial (conditional R2 = 1.00) and the part related to the fixed effects alone (marginal R2) is of 0.02. The model’s intercept, corresponding to cluster = cluster_3, baseline_bipolar_I_dx = 0 and sex = F, is at -14.82 (95% CI (-18.02, -11.62), p < .001). Within this model:

  • The effect of cluster (cluster_1) is statistically significant and negative (beta = -9.88, 95% CI (-19.36, -0.41), p = 0.041; Std. beta = -9.88, 95% CI (-19.36, -0.41))
  • The effect of cluster (cluster_2) is statistically non-significant and positive (beta = 1.19, 95% CI (-2.05, 4.44), p = 0.471; Std. beta = 1.19, 95% CI (-2.05, 4.44))
  • The effect of cluster (cluster_4) is statistically significant and negative (beta = -13.08, 95% CI (-25.32, -0.85), p = 0.036; Std. beta = -13.08, 95% CI (-25.32, -0.85))
  • The effect of cluster (cluster_5) is statistically non-significant and negative (beta = -0.91, 95% CI (-8.69, 6.86), p = 0.818; Std. beta = -0.91, 95% CI (-8.69, 6.86))
  • The effect of baseline bipolar I dx (1) is statistically significant and negative (beta = -11.29, 95% CI (-17.13, -5.45), p < .001; Std. beta = 0.28, 95% CI (-7.01, 7.57))
  • The effect of sex (M) is statistically non-significant and positive (beta = 0.28, 95% CI (-7.01, 7.57), p = 0.940; Std. beta = -11.29, 95% CI (-17.13, -5.45))

Standardized parameters were obtained by fitting the model on a standardized version of the dataset. 95% Confidence Intervals (CIs) and p-values were computed using a Wald z-distribution approximation. The model’s total explanatory power is substantial (conditional R2 = 1.00) and the part related to the fixed effects alone (marginal R2) is of 0.02

Column

Model information

---
title: "Regression model summary from `{easystats}`"
output:
  flexdashboard::flex_dashboard:
    theme:
      version: 4
      # bg: "#101010"
      # fg: "#FDF7F7"
      primary: "#0054AD"
      base_font:
        google: Prompt
      code_font:
        google: JetBrains Mono
params:
  model: model
  check_model_args: check_model_args
  parameters_args: parameters_args
  performance_args: performance_args
---

```{r setup, include=FALSE}
library(flexdashboard)
library(easystats)

# Since not all regression model are supported across all packages, make the
# dashboard chunks more fault-tolerant. E.g. a model might be supported in
# `{parameters}`, but not in `{report}`.
#
# For this reason, `error = TRUE`
knitr::opts_chunk$set(
  error = TRUE,
  out.width = "100%"
)

# helper function for printing `{report}` outputs
bracket_to_parantheses <- function(text) {
  gsub("]", ")", gsub("[", "(", text, fixed = TRUE), fixed = TRUE)
}
```

```{r easydashboard-1}
# Get user-specified model data
model <- params$model

# Is it supported by `{easystats}`? Skip evaluation of the following chunks if not.
is_supported <- insight::is_model_supported(model)

if (!is_supported) {
  unsupported_message <- sprintf(
    "Unfortunately, objects of class `%s` are not yet supported in {easystats}.\n
    For a list of supported models, see `insight::supported_models()`.",
    class(model)[1]
  )
}
```


Model fit
=====================================

Column {data-width=700}
-----------------------------------------------------------------------

### Assumption checks

```{r check-model, eval=is_supported, fig.height=10, fig.width=10}
check_model_args <- c(list(model), params$check_model_args)
# add verbose, if not done yet
if (is.null(check_model_args$verbose)) check_model_args$verbose <- FALSE
tryCatch(
  {
    do.call(performance::check_model, check_model_args)
  },
  error = function(e) {
    cat(insight::format_message(
      "\nSomething did not work as expected. Please file an issue at {.url https://github.com/easystats/easystats/issues/} and post the following output:",
      paste0("\n`", e$message, "`")
    ))
  }
)
```

```{r easydashboard-2, eval=!is_supported}
cat(unsupported_message)
```

Column {data-width=300}
-----------------------------------------------------------------------

### Indices of model fit

```{r easydashboard-3, eval=is_supported}
# {performance}
performance_args <- c(list(model), params$performance_args)
# add verbose, if not done yet
if (is.null(performance_args$verbose)) performance_args$verbose <- FALSE
table_performance <- do.call(performance::performance, performance_args)
print_md(table_performance, layout = "vertical", caption = NULL)
```


```{r easydashboard-4, eval=!is_supported}
cat(unsupported_message)
```

For interpretation of performance metrics, please refer to <a href="https://easystats.github.io/performance/reference/model_performance.html" target="_blank">this documentation</a>.

Parameter estimates
=====================================

Column {data-width=550}
-----------------------------------------------------------------------

### Plot

```{r dot-whisker, eval=is_supported}
# `{parameters}`
parameters_args <- c(list(model), params$parameters_args)
# add verbose, if not done yet
if (is.null(parameters_args$verbose)) parameters_args$verbose <- FALSE
table_parameters <- do.call(parameters::parameters, parameters_args)

plot(table_parameters)
```


```{r easydashboard-5, eval=!is_supported}
cat(unsupported_message)
```

Column {data-width=450}
-----------------------------------------------------------------------

### Tabular summary

```{r easydashboard-6, eval=is_supported}
print_md(table_parameters, caption = NULL)
```


```{r easydashboard-7, eval=!is_supported}
cat(unsupported_message)
```

To find out more about table summary options, please refer to <a href="https://easystats.github.io/parameters/reference/model_parameters.html" target="_blank">this documentation</a>.


Predicted Values
=====================================

Column {data-width=600}
-----------------------------------------------------------------------

### Plot

```{r expected-values, eval=is_supported, fig.height=10, fig.width=10}
# {modelbased}
int_terms <- find_interactions(model, component = "conditional", flatten = TRUE)
con_terms <- find_variables(model)$conditional

if (is.null(int_terms)) {
  model_terms <- con_terms
} else {
  model_terms <- clean_names(int_terms)
  int_terms <- unique(unlist(strsplit(clean_names(int_terms), ":", fixed = TRUE)))
  model_terms <- c(model_terms, setdiff(con_terms, int_terms))
}

# check some exceptions here: logistic regression models with factor response
# usually require the response to be included in the model, else `get_modelmatrix()`
# fails, which is required to compute SE/CI for `get_predicted()`
response <- find_response(model)
minfo <- model_info(model)
model_data <- get_data(model)
include_response <- minfo$is_binomial && minfo$is_logit && is.factor(model_data[[response]])

text_modelbased <- tryCatch(
  {
    lapply(unique(model_terms), function(i) {
      dgrid <- get_datagrid(
        model,
        by = i,
        range = "grid",
        preserve_range = FALSE,
        verbose = FALSE,
        include_response = include_response
      )
      estimate_expectation(model, data = dgrid, verbose = FALSE)
    })
  },
  error = function(e) {
    cat(insight::format_message(
      "\nSomething did not work as expected. Please file an issue at {.url https://github.com/easystats/easystats/issues/} and post the following output:",
      paste0("\n`", e$message, "`")
    ))
    NULL
  }
)

if (!is.null(text_modelbased)) {
  ggplot2::theme_set(theme_modern())
  # all_plots <- lapply(text_modelbased, function(i) {
  #   out <- do.call(visualisation_recipe, c(list(i), modelbased_args))
  #   plot(out) + ggplot2::ggtitle("")
  # })
  all_plots <- lapply(text_modelbased, function(i) {
    out <- visualisation_recipe(i, show_data = "none")
    plot(out) + ggplot2::ggtitle("")
  })

  see::plots(all_plots, n_columns = round(sqrt(length(text_modelbased))))
}
```


```{r easydashboard-8, eval=!is_supported}
cat(unsupported_message)
```

Column {data-width=400}
-----------------------------------------------------------------------

### Tabular summary

```{r easydashboard-9, eval=is_supported, results="asis"}
if (!is.null(text_modelbased)) {
  for (i in text_modelbased) {
    tmp <- print_md(i)
    tmp <- gsub("Variable predicted", "\nVariable predicted", tmp, fixed = TRUE)
    tmp <- gsub("Predictors modulated", "\nPredictors modulated", tmp, fixed = TRUE)
    tmp <- gsub("Predictors controlled", "\nPredictors controlled", tmp, fixed = TRUE)
    print(tmp)
  }
}
```


```{r easydashboard-10, eval=!is_supported}
cat(unsupported_message)
```


Text reports
=====================================

Column {data-width=500}
-----------------------------------------------------------------------

### Textual summary

```{r easydashboard-11, eval=is_supported, results='asis', collapse=TRUE}
# {report}
text_report <- tryCatch(
  {
    report(model, verbose = FALSE)
  },
  error = function(e) {
    cat(insight::format_message(
      "\nSomething did not work as expected. Please file an issue at {.url https://github.com/easystats/easystats/issues/} and post the following output:",
      paste0("\n`", e$message, "`")
    ))
    NULL
  }
)


text_report_performance <- tryCatch(
  {
    report_performance(model, verbose = FALSE)
  },
  error = function(e) {
    cat(insight::format_message(
      "\nSomething did not work as expected. Please file an issue at {.url https://github.com/easystats/easystats/issues/} and post the following output:",
      paste0("\n`", e$message, "`")
    ))
    NULL
  }
)

if (!is.null(text_report)) {
  cat(bracket_to_parantheses(text_report))
  cat("\n")
}

if (!is.null(text_report_performance)) {
  cat(bracket_to_parantheses(text_report_performance))
}
```


```{r easydashboard-12, eval=!is_supported}
cat(unsupported_message)
```

Column {data-width=500}
-----------------------------------------------------------------------

### Model information

```{r easydashboard-13, eval=is_supported}
model_info_data <- insight::model_info(model, verbose = FALSE)
model_info_data <- datawizard::data_to_long(as.data.frame(insight::compact_list(model_info_data)))

DT::datatable(model_info_data)
```

```{r easydashboard-14, eval=!is_supported}
cat(unsupported_message)
```